#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockSupport.h"
#include "../src/Bowling.h"
TEST_GROUP(TestBowling) {
	BOWLING game;
	void setup() {
		Bowling_init(&game);
	}
};

TEST(TestBowling, normal_roll_should_get_score_of_pins) {

	Bowling_roll(&game, 2);
	Bowling_roll(&game, 7);
	for (int i = 0; i < 18; i++)
		Bowling_roll(&game, 0);

	CHECK_EQUAL(9, game.score);
}

TEST(TestBowling, spare_should_add_one_roll_score) {

	Bowling_roll(&game, 5);
	Bowling_roll(&game, 5);
	Bowling_roll(&game, 1);
	for (int i = 0; i < 17; i++)
		Bowling_roll(&game, 0);

	CHECK_EQUAL(12, game.score);
}

TEST(TestBowling, spark_should_add_two_roll_score) {
	Bowling_roll(&game, 10);
	Bowling_roll(&game, 2);
	Bowling_roll(&game, 2);
	for (int i = 0; i < 16; i++)
		Bowling_roll(&game, 0);

	CHECK_EQUAL(18, game.score);
}

TEST(TestBowling, normal_in_last_frame_should_be_over) {
	for (int i = 0; i < 18; i++)
		Bowling_roll(&game, 0);
	Bowling_roll(&game, 2);
	Bowling_roll(&game, 2);

	CHECK_EQUAL(true, game.isGameOver);
	CHECK_EQUAL(4, game.score);
}

TEST(TestBowling, spare_in_last_frame_should_have_one_additional_roll) {
	for (int i = 0; i < 18; i++)
		Bowling_roll(&game, 0);
	Bowling_roll(&game, 2);
	Bowling_roll(&game, 8);

	CHECK_EQUAL(false, game.isGameOver);
	Bowling_roll(&game, 8);

	CHECK_EQUAL(true, game.isGameOver);
	CHECK_EQUAL(18, game.score);
}



TEST(TestBowling, spark_in_last_frame_should_have_two_additional_roll) {
	for (int i = 0; i < 18; i++)
		Bowling_roll(&game, 0);
	Bowling_roll(&game, 10);

	Bowling_roll(&game, 8);
	Bowling_roll(&game, 8);

	CHECK_EQUAL(true, game.isGameOver);
	CHECK_EQUAL(26, game.score);
}
